﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 索引属性
{
    class Program
    {
        static void Main(string[] args)
        {
            contact c = new contact();
            Console.WriteLine("{0}",c.Name);
            c["phone1"] = "123";
            c["phone2"] = "456";
            c["phone3"] = "789";
            c["phone4"] = "000";
            Console.WriteLine(c);
            Console.ReadKey();
        } 
    }
    class contact
    {
        private string name;
        private string phone1;
        private string phone2;
        private string phone3;
        private string phone4;

        public string Name
        {
            get { return name; }
            
        }

        public string this[string type]

        {
            get
            {
                switch (type)
                {
                    case "phone1":return phone1; break; 
                    case "phone2": return phone2; break;
                    case "phone3": return phone3; break;
                    case "phone4": return phone4; break;

                    default:return "None";
                        break;
                }
            }
            set
            {
                switch (type)
                {
                    case "phone1":  phone1=value; break;
                    case "phone2":  phone2=value; break;
                    case "phone3":  phone3=value; break;
                    case "phone4":  phone4=value; break;
         
                }
            }
        }
        public contact()
        {
            name = "张三";
        }
        public override string ToString()
        {
            return string.Format("[{0}][{1}][{2}][{3}][{4}]",name,phone1,phone2,phone3,phone4);
        }

    }
}
